package com.vogue.flowmeter.profile.queue;

import androidx.annotation.NonNull;

import com.vogue.flowmeter.profile.BleProfileManager;

import no.nordicsemi.android.ble.data.Data;

/**
 * 读写队列
 */
public final class WriteQueue extends Queue {

    private static volatile WriteQueue sInstance;
    protected BleProfileManager bleRequest;

    private WriteQueue(BleProfileManager bleManager) {
        bleRequest = bleManager;
    }

    @NonNull
    public static WriteQueue getInstance(BleProfileManager bleManager) {
        if (sInstance != null) {
            return sInstance;
        }
        synchronized (WriteQueue.class) {
            if (sInstance == null) {
                sInstance = new WriteQueue(bleManager);
            }
        }
        return sInstance;
    }

    /**
     * 执行队列任务
     * @param requestTask
     */
    @Override
    public void execute(Data requestTask) {
        bleRequest.readAndWriteData(requestTask);
    }

}
